﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using TierApplication;
using TierService.DEncrypt;

public partial class ForeProgram_register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Load();
            GenerateRandomCode();
        }
    }

    private void GenerateRandomCode()
    {
        Response.Cookies["AreYouHuman"].Value = CaptchaImage.GenerateRandomCode();
    }

    protected void submit_Click(object sender, ImageClickEventArgs e)
    {
        T_ACCOUNT account = new T_ACCOUNT();
        account.ACCOUNTID = mlogin.Text;
        account.ACCOUNTPWD = TranUtils.Encrypt(mpassword.Text);
        account.ACCOUNTNAME = mName.Text;
        account.EMAIL = uemail.Text;
        account.MOBILE = uphone.Text;
        account.SCHOOLID = dlSchool.SelectedValue;
        try
        { 
            account.Add();
            Security.ValidUser(mlogin.Text, mpassword.Text);
        }
        catch (Exception ex)
        {
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), DateTime.Now.ToLongTimeString(), "<script>alert('注册失败！');</script>");
            return;
        }
        Context.Response.Redirect("product.aspx");
    }

    #region
    private void Load()
    { 
        T_SCHOOL schol=new T_SCHOOL();
        dlSchool.DataSource = schol.GetList("");
        dlSchool.DataValueField = "schoolid";
        dlSchool.DataTextField = "schoolshortname";
        dlSchool.DataBind();
        dlSchool.Items.Insert(0, new ListItem("--请选择--", ""));
    }
    #endregion
}